<?php

/*
 *
 *
 * This software has been made FREE by author for the interest of other developers. 
 *      I hope this will help you in coding faster and robust php code
 *            You can modify and redistribute it as you like.
 *              Your comments, suggestions and corrections 
 *                          will be highly 
 *                           APPRECIATED. 
 *                                      Author
 * @author :   Roshan Budhathoki (developer.roshan@gmail.com);
 * @URL    :   <http://www.roshanbudhathoki.com>
 *
 */

function selectbox($name, $options, $params = array()) {
	if ($name == '') {
		return FALSE;
	}
	if (count ( $options ) < 1) {
		return FALSE;
	}
	
	$str = array ();
	$str [] = '<select name="' . $name . '"';
	$par = array ();
	foreach ( $params as $key => $value ) {
		$par [] = $key . '="' . $value . '"';
	}
	$str [] = implode ( " ", $par ) . '>';
	
	// relaease params
	unset ( $par );
	
	foreach ( $options as $key => $value ) {
		if (is_array ( $value )) {
			$vals = array ();
			$vals [] = '<option ';
			foreach ( $value as $i => $j ) {
					$vals [] = $i . '="' . $j . '" ';
			}
			$vals [] = '>';
			$vals[]=$key.'</option>';
			$str[]=implode('',$vals);
			//$str [] = '<option value="' . $value . '">' . $key . '</option>';
		} else {
			$str [] = '<option value="' . $value . '">' . $key . '</option>';
		}
	
	}
	unset ( $options );
	$str [] = '</select>';
	return implode ( '', $str );

}